<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>发布</title>
    <!-- 引入 layui.css 文件 -->
    <link href="//unpkg.com/layui@2.9.11/dist/css/layui.css" rel="stylesheet">
</head>

<body>
<div style="width: 960px;margin: auto;margin-top: 70px;">
    <form id="myForm" class="layui-form layui-form-pane" action="/travelNotes/addTravelNotes" method="post" enctype="multipart/form-data" role="form">
        <div class="layui-form-item">
            <label class="layui-form-label" for="img">选择图片</label>
            <div class="layui-input-block">
                <input type="file" autocomplete="off" lay-verify="required" id="img" name="fileUpload" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label" for="title">标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" autocomplete="off" placeholder="填写标题会被更多人喜欢哦" lay-verify="required" class="layui-input" id="title">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label" for="contend">描述</label>
            <div class="layui-input-block">
                <textarea placeholder="在这里输入描述" class="layui-textarea" id="contend" name="contend"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <button id="submitBtn" class="layui-btn" lay-submit lay-filter="demo2" type="submit">确认</button>
            <a th:href="@{/travelNotes/getTravelNotesList}" class="layui-btn layui-btn-primary">退出</a>
        </div>
    </form>
</div>


<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
    function getCurrentUserStatus(event) {
        event.preventDefault();
        // 发起 AJAX 请求获取当前用户的状态
        $.ajax({
            url: '/user/status',
            type: 'GET',
            success: function (data) {
                // 在成功回调函数中处理获取到的用户状态
                var status = parseInt(data); // 将返回的字符串转换为整数值
                if (status === 1) {
                    // 如果用户状态为1，表示账号异常，禁止发布游记
                    alert('您的账号异常，禁止发布游记');
                } else {
                    // 用户状态为其他值，可以发布游记
                    // 提交表单
                    $('#myForm').off('submit').submit();
                }
            },
            error: function () {
                alert('获取用户状态失败，请重试');
            }
        });
    }

    $(document).ready(function () {
        $('#submitBtn').click(function (event) {
            getCurrentUserStatus(event);
        });
    });
</script>

</body>
</html>
